package com.yongqi.duocai.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yongqi.duocai.entity.Invoice;
import com.yongqi.duocai.mapper.InvoiceMapper;
import com.yongqi.duocai.service.InvoiceService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 夏亮辉
 * @since 2021-06-22
 */
@Service
public class InvoiceServiceImpl extends ServiceImpl<InvoiceMapper, Invoice> implements InvoiceService {

    @Autowired
    private InvoiceMapper invoiceMapper;

    /**
     * 根据 用户id 查询开票信息
     *
     * @param userId
     * @return
     */
    @Override
    public List<Invoice> queryByUserId(Integer userId) {
        QueryWrapper<Invoice> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", userId);
        return invoiceMapper.selectList(queryWrapper);
    }


    /**
     * 获取当前用户的默认发票信息
     *
     * @return
     */
    @Override
    public Invoice queryDefault(Integer userId) {
        QueryWrapper<Invoice> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("is_default", 1)
                    .eq("user_id", userId);
        return invoiceMapper.selectOne(queryWrapper);
    }

    /**
     * 根据条件查询发票抬头
     *
     * @param invoice
     * @return
     */
    @Override
    public List<Invoice> queryOne(Invoice invoice) {
        QueryWrapper<Invoice> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", invoice.getUserId())
                    .eq("name", invoice.getName())
                    .eq("invoice_no", invoice.getInvoiceNo())
                    .eq("bank", invoice.getBank())
                    .eq("bank_no", invoice.getBankNo());
        return invoiceMapper.selectList(queryWrapper);
    }

}
